package com.breakfast.fun.adapter.user;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.breakfast.fun.base.BaseListAdapter;
import com.breakfast.fun.data.entity.user.invite.InviteData;
import com.breakfast.fun.util.ImageUtil;
import com.breakfast.fun.view.widget.RoundImageView;
import com.breakfast.fun.R;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by hp on 2016/8/24.
 */
public class UserInviteAdapter extends BaseListAdapter<InviteData> {

    public UserInviteAdapter(Context context, List<InviteData> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_user_invite, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final InviteData data = getItem(position);
        holder.tvItemInviteName.setText(data.getNickname());
        holder.tvItemInviteMobile.setText(data.getPhone());

        if (data.getHurried() == 0) {
            //未提醒
            holder.tvItemInviteStatusNoRemind.setVisibility(View.GONE);
            holder.tvItemInviteStatusRemind.setVisibility(View.VISIBLE);
        } else {
            //已提醒
            holder.tvItemInviteStatusRemind.setVisibility(View.GONE);
            holder.tvItemInviteStatusNoRemind.setVisibility(View.VISIBLE);
        }

        if (data.getStatus() == 1) {
            //等待下单
            holder.ivItemInviteLine2.setImageResource(R.drawable.bg_black_light);
            holder.tvItemInviteStatusNo.setTextColor(mContext.getResources().getColor(R.color.main_color));
            holder.tvItemInviteStatusOk.setTextColor(mContext.getResources().getColor(R.color.black_light));
        } else {
            //推荐成功
            //等待下单
            holder.ivItemInviteLine2.setImageResource(R.drawable.bg_title_bar);
            holder.tvItemInviteStatusNo.setTextColor(mContext.getResources().getColor(R.color.black_light));
            holder.tvItemInviteStatusOk.setTextColor(mContext.getResources().getColor(R.color.main_color));
        }

        new ImageUtil(mContext).loadCircleImage(data.getPhone(), holder.ivItemInvite);

        holder.tvItemInviteStatusRemind.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(data);
            }
        });

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.iv_item_invite)
        RoundImageView ivItemInvite;
        @Bind(R.id.tv_item_invite_name)
        TextView tvItemInviteName;
        @Bind(R.id.tv_item_invite_mobile)
        TextView tvItemInviteMobile;
        @Bind(R.id.tv_item_invite_status_no_remind)
        TextView tvItemInviteStatusNoRemind;
        @Bind(R.id.tv_item_invite_status_remind)
        TextView tvItemInviteStatusRemind;
        @Bind(R.id.rl_item_invite)
        RelativeLayout rlItemInvite;
        @Bind(R.id.iv_item_invite_line1)
        ImageView ivItemInviteLine1;
        @Bind(R.id.iv_item_invite_line2)
        ImageView ivItemInviteLine2;
        @Bind(R.id.iv_item_invite_circle1)
        ImageView ivItemInviteCircle1;
        @Bind(R.id.iv_item_invite_circle2)
        ImageView ivItemInviteCircle2;
        @Bind(R.id.iv_item_invite_circle3)
        ImageView ivItemInviteCircle3;
        @Bind(R.id.rl_item_invite_schedule)
        RelativeLayout rlItemInviteSchedule;
        @Bind(R.id.tv_item_invite_status_no)
        TextView tvItemInviteStatusNo;
        @Bind(R.id.tv_item_invite_status_ok)
        TextView tvItemInviteStatusOk;
        @Bind(R.id.rl_item_invite_status)
        RelativeLayout rlItemInviteStatus;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
